package i2.application.fmw.cerbere.selenium.pages;

import i2.application.fmw.cerbere.UtilisateurType;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CerberePage {

	private static final Logger LOGGER = LoggerFactory.getLogger(CerberePage.class);
	
	protected WebDriver driver;
	
	@FindBy(name="uid")
	private WebElement identifiant;	

	@FindBy(name="pwd")
	private WebElement password;	

	@FindBy(name="anonyme")
	private WebElement connexionAnonyme;	

	@FindBy(name="Valider")
	private WebElement valider;	

	
	public CerberePage(WebDriver driver) {
		this.driver = driver;
	}
	
	public void open(String url) {
		driver.get(url);
	}

	public void close() {
		driver.quit();
	}
	
	public String getTitle() {
		return driver.getTitle();
	}

	public AccueilApplicationPage login(UtilisateurType utilisateur) {
		LOGGER.debug("begin login");
		this.identifiant.sendKeys(utilisateur.getIdentifiant());
		LOGGER.debug("identifiant send : {}",utilisateur.getIdentifiant());
		this.password.sendKeys(utilisateur.getPasse());
		LOGGER.debug("password send : {}",utilisateur.getPasse());
		valider.click();
		LOGGER.debug("authentification clicked");
		return new AccueilApplicationPage(driver);
	}

	public void clickOnValider() {
		valider.click();
	}

}